//迷宫问题
#include<iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
pair<int,int> Prev[20][20];//用于保存从哪里来的
int main()
{
    int n,m;
    cin>>n>>m;
    vector<vector<int>>map(n,vector<int>(m,0));
    vector<vector<int>>already(n,vector<int>(m,-1));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
            cin>>map[i][j];
    }
    queue<pair<int,int>>way;
    way.push(make_pair(0,0));
    //path.push_back(make_pair(0,0));
    while(!way.empty())
    {
        pair<int,int>top=way.front();
        way.pop();
        already[top.first][top.second]=1;
        int arr[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
        bool flag=false;
        for(int i=0;i<4;i++)
        {
            int nx=top.first+arr[i][0];
            int ny=top.second+arr[i][1];
            if(nx>=n || nx<0 ||ny >=m || ny<0) continue;
            if(map[nx][ny]==0 && already[nx][ny]==-1)
            {
                way.push(make_pair(nx,ny));
                already[nx][ny]=1;
                Prev[nx][ny]=top;
            }
        }
    }
    int x=n-1,y=m-1;
    vector<pair<int,int>>path;
    path.push_back(make_pair(n-1,m-1));
    while(x||y)
    {
        auto t=Prev[x][y];
        path.push_back(t);
        x=t.first,y=t.second;
    }
    reverse(path.begin(),path.end());
    for(auto& e:path)
    {
        cout<<"("<<e.first<<","<<e.second<<")"<<endl;
    }
 
    return 0;
}